/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openjawtech.xscraper.web.action;

import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import com.openjawtech.xscraper.web.dto.FlightsDTO;
import com.openjawtech.xscraper.web.service.FlightsService;

/**
 *
 * @Created on 08-Mar-2009, 21:07:45
 * @author Wenbo.Sun
 */
public class FlightSearchAction extends ActionSupport{

    private static final long serialVersionUID = 1L;

    @Autowired
    private FlightsService flightsService;

    private String departure;
    private String arrival;
    private Date leaveDate;
    private Date returnDate;
    private List<FlightsDTO> flightsResults;

    public void setArrival(String arrival) {
        this.arrival = arrival;
    }

    public void setDeparture(String departure) {
        this.departure = departure;
    }

    public void setLeaveDate(Date leaveDate) {
        this.leaveDate = leaveDate;
    }

    public void setReturnDate(Date returnDate) {
        this.returnDate = returnDate;
    }

    public List<FlightsDTO> getFlightsResults() {
        return flightsResults;
    }

    @Override
    public String execute() throws Exception {
        flightsResults = new ArrayList<FlightsDTO>();
        flightsResults.add(flightsService.searchFlights(departure, arrival, leaveDate));
        if(returnDate != null)
            flightsResults.add(flightsService.searchFlights(arrival, departure, returnDate));
        return SUCCESS;
    }



}
